<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
	<title></title>
	<%@include file="/view/resource.jsp" %>
	<link rel="stylesheet" type="text/css" href="${ctx}/css/base.css">
	<style>

		.depInputClass {
			border: 1px solid #ffa8a8;
			background-color: #fff3f3;
		}
	</style>
	<link rel="stylesheet" href="${ctx}/static/plugins/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css">
	<script type="text/javascript" src="${ctx}/static/plugins/ztree/js/jquery.ztree.core.js"></script>
	<script type="text/javascript" src="${ctx}/static/plugins/ztree/js/jquery.ztree.excheck.js"></script>
</head>
<body>
<form id="entityForm" name="entityForm" action="${ctx}/area/save"
      method="POST">
	<input type="hidden" name="id" value="${id}"/>
	<input type="hidden" name="points" value="${enclosure.points}"/>
	<input type="hidden" name="enclosureType" value="${enclosure.enclosureType}"/>
	<table class="editTable">
		<tr>
			<td class="label" style="width: 60px;min-width: 60px;">地标名称</td>
			<td><input type="text" id="name" name="name" class="topjui-textbox"
			           data-options="required:true,validType:'length[1,30]'"
			           style="width: 200px;" value="${enclosure.name}">
			</td>
		</tr>
		<tr style="visibility: hidden">
			<td class="label" style="width: 60px;min-width: 60px;">半径</td>
			<td><input type="text" id="radius" name="radius" class="topjui-numberbox" data-options="required:true"
			           style="width: 200px;" value="${enclosure.radius}">米
			</td>
		</tr>
	</table>
</form>
<div style="border-width:0px;background:#fff;padding-top: 15px;" class="dialog-button">
	<a href="#" id="btnSave" class="topjui-menubutton" data-options="iconCls:'fa fa-save',
           btnCls:'topjui-btn'">保存</a>
</div>
<div id="depTree-win" class="topjui-dialog" title="分组树形" data-options="closed:true,iconCls:'icon-save',modal:true"
     style="width:500px;height:400px;">
	<ul id="zTree" class="ztree" style="margin: 3px;"></ul>
</div>
<script type="text/javascript" src="${ctx}/js/common/package.js"></script>
<script type="text/javascript" src="${ctx}/js/common/base.js?v=11"></script>
<script type="text/javascript" src="${ctx}/js/common/utility.js"></script>
<script>
	// 对Date的扩展，将 Date 转化为指定格式的String
	// 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符，
	// 年(y)可以用 1-4 个占位符，毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
	// 例子：
	// (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
	// (new Date()).Format("yyyy-M-d h:m:s.S")      ==> 2006-7-2 8:9:4.18
	Date.prototype.Format = function (fmt) { //author: meizz
		var o = {
			"M+": this.getMonth() + 1, //月份
			"d+": this.getDate(), //日
			"h+": this.getHours(), //小时
			"m+": this.getMinutes(), //分
			"s+": this.getSeconds(), //秒
			"q+": Math.floor((this.getMonth() + 3) / 3), //季度
			"S": this.getMilliseconds() //毫秒
		};
		if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
		for (var k in o)
			if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
		return fmt;
	}

	$(function () {
		var strPoints = "${enclosure.points}"; //坐标点的的连接字符串
		var radius =  ${enclosure.radius};

		//alert(strPoints);
		$("#btnSave").click(function () {
			if ($("#entityForm").form('validate')) {
				var data = {};
				Bdth.submitForm($("#entityForm"), data, function (result) {
					if (result.success) {
						$.iMessager.alert('提示', '保存成功.', 'messager-info');
						//保存围栏成功后，在地图上生成带有围栏ID的新围栏
						var enclosure = result.data;//围栏对象
						parent.createMarker(enclosure, strPoints);
						parent.MapTree.refresh();
					}
					else {
						$.iMessager.alert("提示", "保存失败，错误:" + result.msg, 'messager-error');
					}
				});
			}

		})
	});
</script>
<script type="text/javascript">

	/*	var zNodes = [
	 {id: 1, pId: 0, name: "分组 1", open: true},
	 {id: 11, pId: 1, name: "分组 1-1", open: true},
	 {id: 111, pId: 11, name: "分组 1-1-1"},
	 {id: 112, pId: 11, name: "分组 1-1-2"},
	 {id: 12, pId: 1, name: "分组 1-2", open: true},
	 {id: 121, pId: 12, name: "分组 1-2-1"},
	 {id: 122, pId: 12, name: "分组 1-2-2"},
	 ];*/


	//ztree初始化设置
	var setting = {
		view: {
			dblClickExpand: false
		},
		data: {
			simpleData: {
				enable: true,
			}
		},
		callback: {
			onClick: onClick,
			//onCheck: onCheck
		}
	};
	//数据

	function onClick(e, treeId, treeNode) {

		if (treeNode) {
			var name = treeNode.name;
			$("#edit-department").val(name);
			$("#edit-department").removeClass('depInputClass');
			$("#depId").val(treeNode.id);
			hideMenu();
		}

	}

	function onCheck(e, treeId, treeNode) {
		var zTree = $.fn.zTree.getZTreeObj("zTree"),
				nodes = zTree.getCheckedNodes(true),
				v = "",
				id = "";
		code = ""
		for (var i = 0, l = nodes.length; i < l; i++) {
			v += nodes[i].name + ",";
			id += nodes[i].id + ","
			code += nodes[i].code + ","
		}
		if (v.length > 0) {
			v = v.substring(0, v.length - 1);
			id = id.substring(0, id.length - 1);
			code = code.substring(0, code.length - 1);
		}
		$("#edit-department").val(v);
		$("#depId").val(id);
	}

	function showMenu() {
		$("#depTree-win").dialog('open');
		$.post(path + "/dep/depTree", function (data) {
			//console.info(data);
			$.fn.zTree.init($("#zTree"), setting, data);
			var treeObj = $.fn.zTree.getZTreeObj("zTree");
			var nodes = treeObj.getNodes();
			if (nodes.length > 0) {
				for (var i = 0; i < nodes.length; i++) {
					treeObj.expandNode(nodes[i], true, false, false);
				}
			}
		});
	}
	function hideMenu() {
		$("#depTree-win").dialog('close');
	}

</script>
</body>
</html>
